<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-row">
        <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input date" readonly id="start" placeholder="申请时间-起">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input date" readonly id="end" placeholder="申请时间-止">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select id="approve" class="layui-input">
                                    <option value="">是否审核</option>
                                    <option value="1">是</option>
                                    <option value="2">否</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
            </div>
        </div>
    </div>
    <table class="layui-table"
           lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', page: true,limit: 10, id:'cash'}"
           lay-filter="cash">
        <thead>
        <tr>
            <th lay-data="{checkbox:true,fixed: true}"></th>
            <th lay-data="{field:'id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'driver_name', width:80,}">姓名</th>
            <th lay-data="{field:'add_time', width:120, sort: true}">申请时间</th>
            <th lay-data="{field:'money', width:120, sort: true}">提现金额</th>
            <th lay-data="{field:'approve', width:120,align:'center'}">状态</th>
            <th lay-data="{field:'auditor', width:100,align:'center'}">审核员</th>
        </tr>
        </thead>
    </table>




    <script type="application/javascript">
        layui.use(['table', 'laydate', 'form'], function () {
            var table = layui.table
                , form = layui.form
                , laydate = layui.laydate;
            lay('.date').each(function () {
                laydate.render({elem: this, type: 'date', trigger: 'click'});
            });

            //监听工具条
            table.on('tool(cash)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var id = data.record_id;
                if (layEvent === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        var url = "{:url('del')}";
                        obj.del();
                        $.post(url, {'id': id}, function (data) {
                            console.log(data);
                        }, 'json');
                        layer.close(index);
                    });
                }
            });

            var active = {
                search: function () {
                    var approve = $('#approve').val();
                    var pay = $('#pay').val();
                    var start = $('#start').val();
                    var end = $('#end').val();
                    // var bank = $('#bank').val();
                    // var bank_num = $.trim($('#bank_num').val());
                    // var driver_name = $.trim($('#driver_name').val());
                    var reset = $('#reset');
                    if (approve || pay || start || end) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('cash', {
                            url: '/admin/cash/searchIndex',
                            where: {
                                approve: approve,
                                pay: pay,
                                start: start,
                                end: end,
                                // bank: bank,
                                // bank_num: bank_num,
                                driver_id : "{$driver_id}"
                            } //设定异步数据接口的额外参数
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('cash', {
                            url: '/admin/cash/table?action=index', where: {}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //监听审核操作
            form.on('switch(auth_switch)', function (obj) {
                var check = obj.elem;
                var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
                var value = this.value;
                layer.confirm('确定信息正确么?', {icon: 3, title: '提示'},
                    function (index) {
                        var url = "{:url('auth')}";
                        var div = obj.othis.parent('div');
                        var td1 = obj.othis.parents('td').next('td');
                        var td2 = td1.next('td');
                        var name = "{$admin}";
                        $.post(url, {'record_id': value}, function (res) {
                            switch (res['status']){
                                case 1:
                                    var str = "<span style='color: #F581B1;'>已审核</span>";
                                    var str2 = "<input type=\"checkbox\" name=\"record_id\" value=\"{{d.record_id}}\" lay-skin=\"switch\" lay-text=\"是|否\" lay-filter=\"pay_switch\" {{ d.is_pay == 1 ? 'checked disabled' : '' }}>";
                                    div.html(str);
                                    td1.html(name);
                                    td2.html(str2);
                                    form.render('checkbox');
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        }, 'json');
                        layer.close(index);
                    },
                    function (index) {
                        $(check).prop('checked', ori);
                        form.render();
                        layer.close(index);
                    });
            });
            form.on('switch(pay_switch)', function (obj) {
                var check = obj.elem;
                var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
                var value = this.value;
                layer.confirm('确定发放么?', {icon: 3, title: '提示'},
                    function (index) {
                        var url = "{:url('pay')}";
                        var div = obj.othis.parent('div');
                        var td1 = obj.othis.parents('td').next('td');
                        var name = "{$admin}";
                        $.post(url, {'record_id': value}, function (res) {
                            switch (res['status']){
                                case 1:
                                    var str = "<span style='color: #F581B1;'>已发放</span>";
                                    div.html(str);
                                    td1.html(name);
                                    form.render('checkbox');
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        }, 'json');
                        layer.close(index);
                    },
                    function (index) {
                        $(check).prop('checked', ori);
                        form.render();
                        layer.close(index);
                    });
            });
        });

    </script>
</block>
